package com.hangzhou.xyj.ui.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.Toast;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.ui.activity.base.BaseActivity;
import com.hangzhou.xyj.ui.widget.CommonTitleBarView.OnNavRightListener;
import com.hangzhou.xyj.utils.ToastUtil;

public class MyCorrectHobbyActivity extends BaseActivity {
	EditText mEtName;
	Intent intent;

	public static final int SUCCESS = 1;

	@Override
	public void initTop() {
		enableTitle(true, "名字");
		enableRightNav(true, "确定");
	}

	@Override
	public void initLayouts() {
		setContentView(R.layout.activity_correct_name);
	}

	@Override
	public void initViews() {
		mEtName = (EditText) findViewById(R.id.et_name);

	}

	@Override
	public void initDatas() {
		intent = getIntent();
		mEtName.setText(intent.getStringExtra("name"));
		mEtName.setSelection(mEtName.length());
	}

	@Override
	public void initListeners() {
		setOnNavRightListener(new OnNavRightListener() {
			@Override
			public void onNavRight() {
				Intent intent = getIntent();// 获取的是启动该Activity之前的Activity对应的Intent
				String name = mEtName.getText().toString().trim();
				if (TextUtils.isEmpty(name)) {
					ToastUtil.show(MyCorrectHobbyActivity.this, "名字不能为空！",
							Toast.LENGTH_SHORT);
					return;
				}
				intent.putExtra("name", mEtName.getText().toString().trim());
				MyCorrectHobbyActivity.this.setResult(SUCCESS, intent);// 1表示成功
				MyCorrectHobbyActivity.this.finish();// 关闭本窗口
			}
		});
	}
}
